var e = {
    boss_1: 6,
    boss_2: 8,
    boss_3: 7,
    boss_4: 8,
    boss_5: 8,
    com_1_zip: 76,
    com_2_zip: 66,
    com_3_zip: 150,
    com_4_zip: 35,
    common_1: 35,
    common_2: 34,
    common_3: 28,
    common_4: 18,
    common_5: 17,
    common_6: 4,
    common_7: 3,
    common_8: 2,
    config_src_zip: 147,
    config_zip: 54,
    default_file_zip: 1,
    fishing_1: 173,
    fishing_static_0: 24,
    fishing_static_1: 44,
    fishing_static_2: 37,
    fishing_static_3: 24,
    fishing_static_4: 11,
    fishing_static_5: 17,
    font_zip: 86,
    newfish_activity: 32,
    newfish_bag: 15,
    newfish_chestopen: 2,
    newfish_enhanced_weapon: 32,
    newfish_enhanced_weapon_1: 18,
    newfish_enhanced_weapon_2: 12,
    newfish_robbery: 4,
    newfish_robbery_weapon: 6,
    newfish_share: 21,
    newfish_skill: 12,
    newfish_skill_1: 19,
    newfish_skill_2: 6,
    newfish_some_window: 90,
    newfish_task: 16,
    skill_zip: 3,
    sound_zip: 10
};

wxapp.model.loading = function() {
    function o(e) {
        return void 0 === _[e] ? "" : _[e].name + "," + _[e].version;
    }
    var _ = {
        common_1: {
            type: 1,
            version: e.common_1,
            path: "remote_res/",
            name: "common_1"
        },
        common_2: {
            type: 1,
            version: e.common_2,
            path: "remote_res/",
            name: "common_2"
        },
        common_3: {
            type: 1,
            version: e.common_3,
            path: "remote_res/",
            name: "common_3"
        },
        common_4: {
            type: 1,
            version: e.common_4,
            path: "remote_res/",
            name: "common_4"
        },
        common_5: {
            type: 1,
            version: e.common_5,
            path: "remote_res/",
            name: "common_5"
        },
        common_6: {
            type: 1,
            version: e.common_6,
            path: "remote_res/",
            name: "common_6"
        },
        common_7: {
            type: 1,
            version: e.common_7,
            path: "remote_res/",
            name: "common_7"
        },
        boss_1: {
            type: 1,
            version: e.boss_1,
            path: "remote_res/",
            name: "boss_1"
        },
        boss_2: {
            type: 1,
            version: e.boss_2,
            path: "remote_res/",
            name: "boss_2"
        },
        boss_3: {
            type: 1,
            version: e.boss_3,
            path: "remote_res/",
            name: "boss_3"
        },
        boss_4: {
            type: 1,
            version: e.boss_4,
            path: "remote_res/",
            name: "boss_4"
        },
        boss_5: {
            type: 1,
            version: e.boss_5,
            path: "remote_res/",
            name: "boss_5"
        },
        fishing_1: {
            type: 1,
            version: e.fishing_1,
            path: "remote_res/",
            name: "fishing_1"
        },
        fishing_static_0: {
            type: 1,
            version: e.fishing_static_0,
            path: "remote_res/",
            name: "fishing_static_0"
        },
        fishing_static_1: {
            type: 1,
            version: e.fishing_static_1,
            path: "remote_res/",
            name: "fishing_static_1"
        },
        fishing_static_2: {
            type: 1,
            version: e.fishing_static_2,
            path: "remote_res/",
            name: "fishing_static_2"
        },
        fishing_static_3: {
            type: 1,
            version: e.fishing_static_3,
            path: "remote_res/",
            name: "fishing_static_3"
        },
        fishing_static_4: {
            type: 1,
            version: e.fishing_static_4,
            path: "remote_res/",
            name: "fishing_static_4"
        },
        fishing_static_5: {
            type: 1,
            version: e.fishing_static_5,
            path: "remote_res/",
            name: "fishing_static_5"
        },
        com_1_zip: {
            type: 1,
            version: e.com_1_zip,
            path: "remote_res/",
            name: "com_1_zip"
        },
        com_2_zip: {
            type: 1,
            version: e.com_2_zip,
            path: "remote_res/",
            name: "com_2_zip"
        },
        com_3_zip: {
            type: 1,
            version: e.com_3_zip,
            path: "remote_res/",
            name: "com_3_zip"
        },
        com_4_zip: {
            type: 1,
            version: e.com_4_zip,
            path: "remote_res/",
            name: "com_4_zip"
        },
        font_zip: {
            type: 1,
            version: e.font_zip,
            path: "remote_res/",
            name: "font_zip"
        },
        sound_zip: {
            type: 1,
            version: e.sound_zip,
            path: "remote_res/",
            name: "sound_zip"
        },
        skill_zip: {
            type: 1,
            version: e.skill_zip,
            path: "remote_res/",
            name: "skill_zip"
        },
        newfish_some_window: {
            type: 1,
            version: e.newfish_some_window,
            path: "remote_res/",
            name: "newfish_some_window"
        },
        newfish_bag: {
            type: 1,
            version: e.newfish_bag,
            path: "remote_res/",
            name: "newfish_bag"
        },
        newfish_task: {
            type: 1,
            version: e.newfish_task,
            path: "remote_res/",
            name: "newfish_task"
        },
        newfish_enhanced_weapon: {
            type: 1,
            version: e.newfish_enhanced_weapon,
            path: "remote_res/",
            name: "newfish_enhanced_weapon"
        },
        newfish_enhanced_weapon_1: {
            type: 1,
            version: e.newfish_enhanced_weapon_1,
            path: "remote_res/",
            name: "newfish_enhanced_weapon_1"
        },
        newfish_enhanced_weapon_2: {
            type: 1,
            version: e.newfish_enhanced_weapon_2,
            path: "remote_res/",
            name: "newfish_enhanced_weapon_2"
        },
        newfish_robbery: {
            type: 1,
            version: e.newfish_robbery,
            path: "remote_res/",
            name: "newfish_robbery"
        },
        newfish_skill: {
            type: 1,
            version: e.newfish_skill,
            path: "remote_res/",
            name: "newfish_skill"
        },
        newfish_skill_1: {
            type: 1,
            version: e.newfish_skill_1,
            path: "remote_res/",
            name: "newfish_skill_1"
        },
        newfish_share: {
            type: 1,
            version: e.newfish_share,
            path: "remote_res/",
            name: "newfish_share"
        },
        newfish_activity: {
            type: 1,
            version: e.newfish_activity,
            path: "remote_res/",
            name: "newfish_activity"
        },
        config_zip: {
            type: 1,
            version: e.config_zip,
            path: "remote_res/",
            name: "config_zip"
        },
        config_src_zip: {
            type: 1,
            version: e.config_src_zip,
            path: "remote_res/",
            name: "config_src_zip"
        },
        default_file_zip: {
            type: 1,
            version: e.default_file_zip,
            path: "remote_res/",
            name: "default_file_zip"
        }
    };
    for (var n in _) _[n].path = newfish.prePath + _[n].path;
    e = null;
    var s = {
        lobby: [],
        backstage: [],
        backstage1: [],
        backstage_enhanced_weapon: [ "newfish_enhanced_weapon", "newfish_enhanced_weapon_1", "newfish_enhanced_weapon_2" ],
        backstage_skill: [ "newfish_skill", "newfish_skill_1", "skill_zip" ],
        backstage_activity: [ "newfish_activity" ],
        backstage_some_window: [ "newfish_some_window" ],
        backstage_share: [ "newfish_share" ],
        backstage_bag: [ "newfish_bag" ],
        backstage_task: [ "newfish_task" ],
        backstage_config_zip: [ "config_zip" ],
        backstage_fishing_1: [ "fishing_static_0", "fishing_static_1", "fishing_static_2", "fishing_static_3", "fishing_static_4", "fishing_static_5", "fishing_1", "common_1", "boss_1", "common_2", "boss_2", "common_3", "boss_3", "common_4", "boss_4", "boss_5" ],
        game_44301: [ "common_7", "boss_4" ],
        game_44001: [ "common_1", "boss_1", "common_2" ],
        game_44002: [ "common_1", "boss_1", "common_2", "boss_2" ],
        game_44003: [ "common_1", "boss_1", "common_2", "boss_2", "common_3", "boss_3", "common_4" ],
        game_44004: [ "common_1", "boss_1", "common_2", "boss_2", "common_3", "boss_3", "common_4", "boss_4", "boss_5" ],
        game_44005: [ "common_1", "boss_1", "common_2", "boss_2", "common_3", "boss_3", "common_4", "boss_4", "boss_5" ],
        game_44104: [ "common_1" ],
        game_44101: [ "common_1", "common_2", "common_3", "common_4" ],
        game_44102: [ "common_1", "common_2", "common_3" ],
        game_44103: [ "common_1", "common_2", "common_3", "common_4", "common_5", "common_6" ],
        game_44401: [ "common_1", "common_2", "common_3", "boss_1" ],
        game_44402: [ "common_1", "common_2", "common_3", "boss_1", "boss_2" ],
        game_44403: [ "common_1", "common_2", "common_3", "common_4", "common_5", "boss_2", "boss_3" ],
        game_44404: [ "common_1", "common_2", "common_3", "common_4", "common_5", "boss_3", "boss_4", "boss_5" ],
        game_44405: [ "common_1", "common_2", "common_3", "common_4", "common_5", "common_6", "boss_3", "boss_4", "boss_5" ],
        game_44499: [ "common_1", "common_2", "boss_5" ]
    };
    !function() {
        var e = {
            backstage_enhanced_weapon: 1,
            backstage_skill: 2,
            backstage_activity: 3,
            backstage_some_window: 4,
            backstage_share: 5,
            backstage_bag: 6,
            backstage_task: 7,
            backstage: 8,
            backstage1: 9,
            backstage_config_zip: 10,
            backstage_fishing_1: 11
        }, o = [ "font_zip", "com_1_zip", "com_2_zip", "com_3_zip", "com_4_zip", "config_src_zip", "default_file_zip", "sound_zip" ], _ = [ "newfish_enhanced_weapon", "newfish_enhanced_weapon_1", "newfish_enhanced_weapon_2", "newfish_robbery", "config_zip", "newfish_skill", "newfish_skill_1", "skill_zip", "fishing_static_0", "fishing_static_1", "fishing_static_2", "fishing_static_3", "fishing_static_4", "fishing_static_5", "fishing_1" ];
        for (var n in s) if (!(n in e)) for (i = 0; i < o.length; i++) s[n].push(o[i]);
        for (var n in s) if (!(n in e) && "lobby" !== n) for (var i = 0; i < _.length; i++) s[n].push(_[i]);
    }();
    var i = "-1", t = {}, a = {}, m = function() {
        t = {};
    }, r = function(e) {
        delete t[e];
    }, c = function() {
        wxapp.tools.storage.set("storage_key_res_zip", JSON.stringify(t));
    }, p = function(e) {
        return t[e];
    }, h = function() {
        return "1.3" == i;
    }, f = function() {
        i = "1.3", wxapp.tools.storage.set("storage_key_res_major_version", i);
    }, g = function() {
        var e = [];
        for (var n in t) {
            var s = !1;
            for (var i in _) if (n === o(i)) {
                s = !0;
                break;
            }
            s || e.push(n);
        }
        return e;
    }, w = function(e) {
        return !!t[e];
    }, l = function(e) {
        for (var _ = s[e], n = [], i = 0; i < _.length; i++) {
            r = o(_[i]);
            w(r) || n.push(r);
        }
        for (var t = Object.keys(a), i = 0, m = t.length; i < m; i++) if (a[t[i]] >= 1) {
            var r = o(t[i]);
            -1 === n.indexOf(r) && (n.push(r), delete a[t[i]]);
        }
        return n;
    }, b = function(e, o) {
        var n = !0;
        !1 === o && (n = !1);
        var s = {
            _abort: !1,
            data: null,
            downloadTask: null,
            isAbort: function() {
                return this._abort;
            },
            abort: function() {
                this._abort = !0, this.downloadTask && this.downloadTask.abort();
            }
        }, i = function(o) {
            n ? tywx.NotificationCenter.trigger(tywx.EventType.EVT_LOADING_DOWNLOAD_FINISH, o) : tywx.NotificationCenter.trigger(tywx.EventType.EVT_BACKSTAGE_DOWNLOAD_FINISH, o, e);
        };
        newfish.LOGD("xxx_convertFileList_moduleId=" + e);
        var a = l(e);
        if (0 !== a.length) {
            var m = [];
            s.data = m;
            for (var r in a) {
                var c = _[a[r].split(",")[0]];
                if (1 === c.type) m.push({
                    type: 1,
                    path: c.path + c.name + "_v" + c.version + ".zip",
                    key: c.name + "," + c.version
                }); else if (2 === c.type) {
                    var p = c.path + c.name + "_v" + c.version + "/";
                    m.push({
                        type: 2,
                        path: p + c.name + "_v" + c.version + ".json",
                        folder: p,
                        key: c.name + "," + c.version
                    });
                }
            }
            return wxapp.tools.file.download(s, function(e) {
                i(!!e);
            }, function(o) {
                n ? tywx.NotificationCenter.trigger(tywx.EventType.EVT_LOADING_DOWNLOAD_PROGRESS, o) : tywx.NotificationCenter.trigger(tywx.EventType.EVT_BACKSTAGE_DOWNLOAD_PROGRESS, o, e);
            }, function(e, o) {
                t[e] = o.filelist;
                var _ = JSON.stringify(t);
                wxapp.tools.storage.setAsync("storage_key_res_zip", _, function(e, o) {
                    console.error("存储失败key", e);
                });
            }), s;
        }
        i(!0);
    };
    return {
        startDownloadModule: b,
        isAuthorizeLogin: !1,
        initLocalInfo: function() {
            var e = wxapp.tools.storage.get("storage_key_res_major_version");
            e && (i = e), (e = wxapp.tools.storage.get("storage_key_res_zip")) && (t = JSON.parse(e));
        },
        removeAllLocalResInfo: m,
        saveLocalResInfo: c,
        removeLocalResInfo: r,
        checkResInfo: l,
        getKeysNeedDownload: l,
        convertFileList: function(e) {
            "game_0" === e && (e = "lobby");
            for (var o = s[e], _ = [], n = 0; n < o.length; n++) {
                var i = res_zip_file_list[o[n]];
                for (var t in i) _.push(i[t]);
            }
            return _;
        },
        disposeLoaclInfo: function(e) {
            (!h() || wxapp.alwaysDelete50MbRes || e) && (wxapp.twarn("app", "删除用户res目录"), wxapp.tools.fileSystem.delUserFolder2("res/"), 
            m(), c(), f());
            var o = g();
            if (o.length > 0) for (var _ = 0; _ < o.length; _++) {
                var n = o[_];
                wxapp.twarn("app", "删除没用的zip", n);
                for (var s = p(n), i = 0; i < s.length; i++) {
                    var t = s[i];
                    wxapp.tools.fileSystem.delUserFile(t);
                }
                r(n), c();
            }
        },
        checkDownloaded: function(e) {
            var _ = o(e);
            return "" === _ || !!w(_);
        },
        startBackstageDownload: function(e) {
            return b(e, !1);
        },
        markErrorLocalResInfo: function(e) {
            if (e in a ? a[e]++ : a[e] = 1, a[e] >= 1) {
                var _ = o(e);
                _ in t && (r(_), c());
            }
        }
    };
};